import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/store/auth_store.dart';
import 'package:bxultimate/widgets/mk_card_container.dart';
import 'package:bxultimate/widgets/mk_list_cell_item.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class UserInformationIndexPage extends StatefulWidget {
  const UserInformationIndexPage({Key? key}) : super(key: key);

  @override
  State<UserInformationIndexPage> createState() =>
      _UserInformationIndexPageState();
}

class _UserInformationIndexPageState extends State<UserInformationIndexPage> {
  final controller = Get.find<UserInformationIndexController>();
  final state = Get.find<UserInformationIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
        child: Scaffold(
            backgroundColor: Colors.transparent,
            appBar: TDNavBar(
              title: '个人资料',
              backgroundColor: Colors.transparent,
            ),
            body: ListView(
              children: <Widget>[
                _buildNav(),
              ],
            )));
  }

  _buildNav() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(
          horizontal: AppTheme.iDefaultPadding,
          vertical: AppTheme.iDefaultPadding / 2),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MkListCellItem(
            height: 70,
            ext: Obx(() => Container(
                  padding: EdgeInsets.all(4),
                  decoration: BoxDecoration(
                      border: Border.all(color: Colors.white, width: 3),
                      borderRadius: BorderRadius.all(Radius.circular(34))),
                  child: CircleAvatar(
                    radius: 34,
                    backgroundImage: NetworkImage(AuthStore.to.getUserAvatar()),
                    foregroundColor: Colors.white,
                  ),
                )),
            value: '头像',
            press:  (){
              controller.updateAvatar(context);
            },
          ),
          MkListCellItem(
            value: '昵称',
            ext: Obx(()=>Text("${AuthStore.to.profile.nickname}")),
            press: controller.updateNickName,
          ),
          MkListCellItem(
            value: '实名认证',
            ext: Obx(()=>state.userIdentity.status == 1
                ? TDTag(
              '已认证',
              theme: TDTagTheme.success,
            )
                : TDTag(
              '未认证',
              theme: TDTagTheme.danger,
            )),
            press: () {},
          ),
          MkListCellItem(
            value: '个人资料',
            press: () {
              Get.toNamed(RouterName.userInformationComplete);
            },
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<UserInformationIndexController>();
    super.dispose();
  }
}
